package com.flex.core.model.img
{
	import com.flex.core.event.img.MimageEvent;

	import flash.events.Event;

	import mx.controls.Image;
	import mx.core.mx_internal;
	use namespace mx_internal;

	public class Mimage extends Image
	{
		public var completeEvent:String;

//		public var mimageEvent:MimageEvent=new MimageEvent();

		public function Mimage(completeEvent:String)
		{
			this.completeEvent=completeEvent;
			super();
			this.addEventListener("imageLoadComplete", ImageLoadComplete);
		}

		/**
		 * i get this function from an article, this just listen when the image is complete,
		 *  then dispacth event by property completeEvent
		 */
		override mx_internal function contentLoaderInfo_completeEventHandler(event:Event):void
		{
			super.contentLoaderInfo_completeEventHandler(event);
			this.dispatchEvent(new Event("imageLoadComplete"));
		}
		
		public function ImageLoadComplete(e:Event):void
		{
			var img:Mimage=e.currentTarget as Mimage;
			var mimageEvent:MimageEvent=new MimageEvent(img);
			mimageEvent.dispatchEvent(new Event(completeEvent));
		}
	}
}